package ym.ecrm.core.domain.systemManagement;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import ym.ecrm.core.domain.base.BaseEntity;

/**
 * 组织结构类（即部门）
 * @author Princess
 * @version 1.0
 */
@Entity
@Table(name="t_organization")
public class Organization extends BaseEntity {

	/**
	 * organizationCode 组织结构编号
	 */
	private String organizationCode;
	/**
	 * name 组织名称
	 */
	private String name;
	/**
	 * telephone 电话
	 */
	private String telephone;
	/**
	 * fax 传真号码
	 */
	private String fax;
	/**
	 * address 详细地址
	 */
	private String address;

	@ManyToOne(targetEntity=Organization.class,
			cascade={CascadeType.PERSIST,CascadeType.MERGE})
	@JoinColumn(name="parent_id")
	private Organization parent;

	@OneToMany(targetEntity=Organization.class,
			cascade={CascadeType.PERSIST,CascadeType.MERGE},
			fetch=FetchType.LAZY,
			mappedBy="parent")
	@Cascade(value=org.hibernate.annotations.CascadeType.DELETE)
	private Set<Organization> childs = new HashSet<Organization>();

	@OneToMany(targetEntity=User.class,
			fetch=FetchType.LAZY)
	@JoinTable(name="tr_organization_user",
			joinColumns=@JoinColumn(name="organizationId"),
			inverseJoinColumns=@JoinColumn(name="userId"))
	private Set<User> member = new HashSet<User>();

	public String getOrganizationCode() {
		return organizationCode;
	}

	public void setOrganizationCode(String organizationCode) {
		this.organizationCode = organizationCode;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Organization getParent() {
		return parent;
	}

	public void setParent(Organization parent) {
		this.parent = parent;
	}

	public Set<Organization> getChilds() {
		return childs;
	}

	public void setChilds(Set<Organization> childs) {
		this.childs = childs;
	}

	public Set<User> getMember() {
		return member;
	}

	public void setMember(Set<User> member) {
		this.member = member;
	}

}
